package com.briup.searchengine.handle;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author adam
 * @date 2023/2/15
 */
public class URLUtils {

    //    将nutch爬取到的网址数据 转换成常见格式
    public static String showUrl(String s) {
        String[] split = s.split(":");
        if (split.length == 2) {
            String[] domain = split[0].split("[.]");
            List<String> list = Arrays.asList(domain);
            Collections.reverse(list);
            String rs = "";
            for (String s1 : list) {
                rs += s1 + ".";
            }
            rs = rs.substring(0, rs.length() - 1);
            String proto = split[1].substring(0, split[1].indexOf("/"));
            String res = split[1].substring(split[1].indexOf("/"), split[1].length());
            return proto + "://" + rs.trim() + res.trim();
        }
        return null;
    }


}
